<%@ page language="java" contentType="text/html; charset=UTF-8"  pageEncoding="UTF-8"%>
<%@ include file="/common/include.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" src='<s:url value="/scripts/CustomTreeUI.js" includeParams="none"/>'></script>
<link rel="stylesheet" type="text/css" href='<s:url value="/scripts/column-tree.css" includeParams="none"/>'/>
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/css/css.css">
<script src='<s:url value="/dwr/interface/commonSearchListService.js" includeParams="none"/>' type="text/javascript"></script>

<title>主题列表</title>
<script>
var  highlightcolor='#F8EABE';
//此处clickcolor只能用win系统颜色代码才能成功,如果用#xxxxxx的代码就不行,还没搞清楚为什么:(
var  clickcolor='#fff';
function  changeto(){
source=event.srcElement;
if  (source.tagName=="TR"||source.tagName=="TABLE")
return;
while(source.tagName!="TD")
source=source.parentElement;
source=source.parentElement;
cs  =  source.children;
//alert(cs.length);
if  (cs[1].style.backgroundColor!=highlightcolor&&source.id!="nc"&&cs[1].style.backgroundColor!=clickcolor)
for(i=0;i<cs.length;i++){
	cs[i].style.backgroundColor=highlightcolor;
}
}

function  changeback(){
source=event.srcElement;
if  (event.fromElement.contains(event.toElement)||source.contains(event.toElement)||source.id=="nc")
return
if  (event.toElement!=source&&cs[1].style.backgroundColor!=clickcolor)
//source.style.backgroundColor=originalcolor
for(i=0;i<cs.length;i++){
	cs[i].style.backgroundColor="";
}
}

function  clickto(){
source=event.srcElement;
if  (source.tagName=="TR"||source.tagName=="TABLE")
return;
while(source.tagName!="TD")
source=source.parentElement;
source=source.parentElement;
cs  =  source.children;
//alert(cs.length);
if  (cs[1].style.backgroundColor!=clickcolor&&source.id!="nc")
for(i=0;i<cs.length;i++){
	cs[i].style.backgroundColor=clickcolor;
}
else
for(i=0;i<cs.length;i++){
	cs[i].style.backgroundColor="";
}
}


function openTree(strCompareCondId){
		var Tree = Ext.tree;
   		var tree = new Tree.TreePanel({       
	        autoScroll:true,
	        animate:true,
	        enableDD:true,
	        containerScroll: true,
	        rootVisible:false,    
	        loader: new Tree.TreeLoader({    
	          dataUrl: '<s:url namespace="/querythemes" action="qdDomainSearch!load4BuilderTree.action?strCompareCondId"/>',    
	          baseParams:{strCompareCondId:strCompareCondId}
      		})
   	 	});
		
   		// set the root node
	    var root = new Tree.AsyncTreeNode({
	        text: '功能',
	        draggable:false,
	        id:'-1'
	    });
	    tree.setRootNode(root);
		
		var win = new Ext.Window({
		                //applyTo     : 'hello-win',
		                title:"选择查询条件",
		                layout      : 'fit',
		                width       : 700,
		                height		:400,
		                closable:false, 
		                closeAction :'close',
		                modal:true, 
		                plain       : true,
		                items:tree,
		                buttons: [
		                 {
		                    text     : '展开',
		                    disabled : false,
		                    handler  :function(){
		                   	tree.root.expand(true,false);
		                    }
		                },
		                {
		                    text     : '收缩',
		                    disabled : false,
		                    handler  :function(){
		                   	tree.root.collapse(true,false);
		                    }
		                },
        
		                {
		                    text     : '确定',
		                    disabled : false,
		                    handler  :function(){                 		                    	
		                    	var ids = "";
		                    	var names = "";
		                    	var checked = [];		                    		                    	
		                    	for (var i = 0; i < tree.getRootNode().childNodes.length; i++){		                    		     
						               checked = checked.concat(getChecked(tree.getRootNode().childNodes[i]));						               
						        }
						        
						        for(var i=0;i<checked.length;i++){
						        	var n = checked[i];
						        	if(ids==""){
						        		ids ="'"+n.id+"'";
						        	}else{
						        		ids = ids +",'"+n.id+"'";
						        	}
						        	
						        	if(names==""){
						        		names =n.text;
						        	}else{
						        		names = names +","+n.text;
						        	}
						        }
						        
						        document.getElementById("searchConditionValueIds_"+strCompareCondId).value=ids;
	    						document.getElementById("divid_"+strCompareCondId).innerHTML=names;
		                        win.close();
		                    }
		                },
		                {
		                    text     : '取消',
		                    disabled : false,
		                    handler  :function(){
		                    //Ext.get("cpi").dom.value='';//Ext.get("cpn").dom.value='';
		                    win.close();}
		                }]
		  });	
		  
		 tree.on('checkchange', function(node, checked) { 
			node.expand();    
			node.attributes.checked = checked;    
			node.eachChild(function(child) {             
			child.ui.toggleCheck(checked);               
			child.attributes.checked = checked;   
			child.fireEvent('checkchange', child, checked);          
		});}, tree); 

		tree.on('click', function(node, e) {  
			if (!node.isLeaf()){
				node.toggle(); 
			}
		 });  
		 
	    win.show();
	}
	
	/**  
     * 取得所有子节点中checked为true的节点(TreeNode) 包括本节点  
	 */  
	function getChecked(node){ 
        var checked = [];  
        if (node.getUI().isChecked()){  
           checked.push(node);  
        }  
        if (!node.isLeaf()){  
          for (var i = 0; i < node.childNodes.length; i++){  
               checked = checked.concat(getChecked(node.childNodes[i]));  
          }  
       }  
       return checked;  
   }
	
	
	function doHightSearch(){
		document.getElementById("s_user_form").action="qdDomainSearch!load4HightSearch.action";		
		document.getElementById("s_user_form").submit();
	}
	
	
	function doSearch(){
		document.getElementById("pageSize").value = document.getElementById("pageSizeId").value;
		//document.getElementById("pageSize").value = "1";
		document.getElementById("s_user_form").action="qdDomainSearch!doSearch.action";		
		document.getElementById("s_user_form").submit();
	}
	
	function processQdCompareType(searchFieldId,ids){
		removeoptions(ids);		
		commonSearchListService.getSearchConditionTypeSQLList(searchFieldId,function(data){		
			if(data && data!="undefined" && data!=undefined){
				removeoptions(ids);
	    		for(var i=0;i<data.length;i++){
	    			var ip = 0;
	    			var code = "";
	    			var name = "";
	    			for(var property in data[i]){	    				 				
	    				if(ip*1 == 0)
  							code = data[i][property];
  						if(ip*1 == 1)
  							name = data[i][property]; 
  						ip=ip*1+1; 
	    			}
	    			
	    			
	    			var optionsvalue=code;   
					var optionstext=name; 
					//alert("optionsvalue=="+optionsvalue+"   optionstext=="+optionstext);				
					addoptions(ids,optionstext,optionsvalue)   
	    		}
	    	}
		});	
	}
		
	function addoptions(objectid,textvalue,optionsvalue){   
		var optionsSubObjects=document.getElementById(objectid);   
		var hasexist=0;   
		for(var o=0;o<optionsSubObjects.length;o++){   
		 	var optionsvalue_sub=optionsSubObjects.options[o].text;   
		 	if(optionsvalue_sub==textvalue)   
		 		hasexist+=1;   
		}   
		if(hasexist==0){   
		 optionsSubObjects.add(new Option(textvalue, optionsvalue));   
		}   
	}   
	
	function removeoptions(objectid){
		var optionsObjects=document.getElementById(objectid);
		for(var o=optionsObjects.length-1;o>=1;o--){	    	
			optionsObjects.options.remove(o);	    	
	    }    	
	}
	
	function openList(ids){		 		
		var ret=window.showModalDialog("<%=request.getContextPath()%>/querythemes/qdDomainSearch!load4OpenList.action?strCompareCondId="+ids,'','dialogWidth:900px;dialogHeight:600px;dialogTop:100;dialogLeft:200;');
		if(typeof(ret)=="undefined") return;
        document.getElementById("searchConditionValueIds_"+ids).value=ret[0];
	    document.getElementById("divid_"+ids).innerHTML=ret[1];	    
	}
	
	function tt(sql,ids){
		alert("sql=="+sql);
		alert("ids=="+ids);
	}
	
</script>
</head>
<body>
<div class="main">
<s:form id="s_user_form" namespace="/querythemes" action="qdDomainSearch!doSearch.action">
<div class="main_title"><b>你当前的位置：</b><s:property value="title" /></div>
	<s:hidden name="pageSize" id="pageSize"/>
	<s:hidden name="qdDomain.id" id="qdDomain.id"/>
	<!-- <table  cellpadding="1" cellspacing="1" class="search">
      <tr class="listr2">
        <td align="right" style="width:25%">主题名称:</td>
        <td align="left" class="listr5">
        	<s:property value="qdDomain.name"/>        	
        </td> 
      </tr>        
      <tr class="listr2">
        <td align="right">主题描述</td>
        <td align="left" class="listr5">
        	<s:property value="qdDomain.descript"/>
        </td>               
      </tr>
    </table>
    <br>-->
   
    <div class="main_title"><b>已保存查询</b></div>
       
	<s:if test="hisConditionListSize==0">
		<table  cellpadding="1" cellspacing="1" class="search">
	      <tr class="listr2">
	        <td align="left" ><i>&nbsp;&nbsp;无</i></td>	        
	      </tr>
	    </table>
	</s:if>
	<s:if test="hisConditionListSize>0">
		<table id="res-table" align="center"  cellpadding="1" cellspacing="1" class="tablelist"  onmouseover="changeto()"  onmouseout="changeback()">
		  <tr class="toptitle">
		  	<td>序号</td>
		  	<!-- <td>保存者</td>  -->
		    <td>条件名称</td>
			<!--<td>条件描述</td>	 -->
			<td>操作</td>
		  </tr>
		  <tbody>
			<s:iterator value="hisConditionList" status="status">
				<s:if test="#status.even">
				 <tr class="listr1" onmouseover="this.className='listr3'" onmouseout="this.className='listr1'">
				</s:if>
				<s:else>
				 <tr class="listr2" onmouseover="this.className='listr3'" onmouseout="this.className='listr2'">
				</s:else>
					<td>&nbsp;<s:property value="#status.index+1" /></td>
					<!--<td>&nbsp;
						<s:property value="%{top.getUserName()}"/>
					</td>-->
					<td>&nbsp;<s:property value="condname" /></td>	
					<!--<td>&nbsp;<s:property value="descript" /></td>	-->	
					<td>&nbsp;
						<s:url id="deleteUrl" namespace="/querythemes"
							action="qdDomainSearch!deleteHisConditionFromInitPage.action" includeParams="false">
							<s:param name="qdHisConditionId">
								<s:property value="id" />
							</s:param>
							<s:param name="strDomainId">
								<s:property value="qdDomain.id" />
							</s:param>								
						</s:url>
						<s:url id="queryUrl" namespace="/querythemes"
							action="qdDomainSearch!doSearchByHisCondition.action" includeParams="false">
							<s:param name="qdHisConditionId">
								<s:property value="id" />
							</s:param>
							<s:param name="qdDomain.id">
								<s:property value="qdDomain.id" />
							</s:param>							
						</s:url>
						<s:a href='%{queryUrl}'>查询</s:a>
						&nbsp; / &nbsp;
						<s:a href='%{deleteUrl}'>删除</s:a>
					</td>
				</tr>
			 </s:iterator>
		   </tbody>
		</table>
	</s:if>
	

 	<div class="main_title"><b>简单查询 (<a href="##" onclick="doHightSearch()"><i><b>高级查询</b></i></a>)</b>
 		<div style="width:20%;float:right;margin-top:-21px;text-align:right;padding-right:5px">
 			&nbsp;每页记录数:<s:select id="pageSizeId"  style="width:50px; vertical-align: middle" list='#{20:"20",50:"50",100:"100",200:"200",300:"300",500:"500"}' name="pageSizeName"></s:select>
 		</div>
 	</div>
 	
 	<s:if test="searchConditionListSize==0">
		<table  cellpadding="1" cellspacing="1" class="search">
	      <tr class="listr2">
	        <td align="left" ><i>&nbsp;&nbsp;无</i></td>	        
	      </tr>
	    </table>
	</s:if>	
	
	<s:if test="searchConditionListSize>0">
		<table id="res-table" align="center" cellpadding="1" cellspacing="1" class="tablelist"  onmouseover="changeto()"  onmouseout="changeback()">
			 <tr class="toptitle">
			 	<td width="5%">序号</td>
			  	<td width="10%">条件名称</td>
			    <td width="20%">条件方式</td>
				<td>条件值</td>	
				<td width="5%">选择</td>
			  </tr>
			  <tbody>
				<s:iterator value="searchConditionList" status="status">
					<s:if test="#status.even">
					 <tr class="listr1" onmouseover="this.className='listr3'" onmouseout="this.className='listr1'">
					</s:if>
					<s:else>
					 <tr class="listr2" onmouseover="this.className='listr3'" onmouseout="this.className='listr2'">
					</s:else>
						<td>
							<s:property value="#status.index+1" />
							<s:hidden name="searchConditionIdNames" id="searchConditionIdIds_%{id}" value="%{id}"></s:hidden>							
						</td>
						<td>
							&nbsp;<s:property value="name" />
						</td>
						<td>
							<!-- 0:输入值 -->
							<s:if test="TQdComparetype.id==0">
								<s:select  cssClass="searchSelect"  name="searchConditionNames" id="searchConditionIds_%{id}" list='#{"":"---请选择---","=":"等于","<>":"不等于",">":"大于",">=":"大于等于","<":"小于","<=":"小于等于","like":"包含","is":"为空","is not":"不为空"}'></s:select>
							</s:if>
							<!-- 1:下拉框 -->
							<s:if test="TQdComparetype.id==1">
								<s:select  cssClass="searchSelect"  name="searchConditionNames" id="searchConditionIds_%{id}" list='#{"":"---请选择---","=":"等于","<>":"不等于",">":"大于",">=":"大于等于","<":"小于","<=":"小于等于","like":"包含","is":"为空","is not":"不为空"}'></s:select>
							</s:if>
							<!-- 2:多选框 -->
							<s:if test="TQdComparetype.id==2">
								<s:select  cssClass="searchSelect"  name="searchConditionNames" id="searchConditionIds_%{id}" list='#{"":"---请选择---","IN":"属于","NOT IN":"不属于"}'></s:select>
							</s:if>
							<!-- 3:宏变量 -->
							<s:if test="TQdComparetype.id==3">
							</s:if>
							<!-- 4:树形复选 -->
							<s:if test="TQdComparetype.id==4">
								<s:select  cssClass="searchSelect"  name="searchConditionNames" id="searchConditionIds_%{id}" list='#{"":"---请选择---","IN":"属于","NOT IN":"不属于"}'></s:select>
							</s:if>						
						</td>
						<td>							
							<!-- 0:输入值 -->
							<s:if test="TQdComparetype.id==0">
								<s:textfield cssClass="leaf" name="searchConditionValueNames" id="searchConditionValueIds_%{id}"/>
							</s:if>
							<!-- 1:下拉框 -->
							<s:if test="TQdComparetype.id==1">
								<s:select  cssClass="searchSelect"  name="searchConditionValueNames" id="searchConditionValueIds_%{id}" list='#{"":"---请选择---"}'></s:select>
								<script>
									processQdCompareType('<s:property value="id" />','searchConditionValueIds_<s:property value="id" />');
								</script>
							</s:if>
							<!-- 2:多选框 -->
							<s:if test="TQdComparetype.id==2">
								<s:hidden name="searchConditionValueNames" id="searchConditionValueIds_%{id}"></s:hidden>
								<div id="divid_<s:property value="id" />"></div>
							</s:if>
							<!-- 3:宏变量 -->
							<s:if test="TQdComparetype.id==3">
							
							</s:if>
							<!-- 4:树形复选 -->
							<s:if test="TQdComparetype.id==4">
								<s:hidden name="searchConditionValueNames" id="searchConditionValueIds_%{id}"></s:hidden>
								<div id="divid_<s:property value="id" />"></div>
							</s:if>
						</td>								
						<td>&nbsp;
							<!-- 2:多选框 -->
							<s:if test="TQdComparetype.id==2">
								<s:a href="##" onclick="openList('%{id}')">浏览</s:a>
							</s:if>
							
							<!-- 4:树形复选 -->
							<s:if test="TQdComparetype.id==4">
								<s:a href="##" onclick="openTree('%{id}')">浏览</s:a>
							</s:if>
						</td>
					</tr>
				 </s:iterator>
			   </tbody>
			</table>
	</s:if>
	
 	<div class="tableHeader4">
 		 <table>
 		 	<tr style="width:100%">
 		 		<!--
 		 		<td style="width:25%">
 		 			&nbsp;
 		 		</td>
 		 		-->
 		 		<td align="center">
 		 			<input name="" type="button" value="查 询" class="searchbtn" onmouseover="this.className='searchbtn_hover'" onmouseout="this.className='searchbtn'"   onclick="doSearch()"/>
 		 		</td>
 		 		<!--
 		 		<td align="right">
 		 			&nbsp;每页记录数:<s:select id="pageSizeId" list='#{20:"20",50:"50",100:"100",200:"200",300:"300",500:"500"}' name="pageSizeName"></s:select>
 		 		</td>
 		 		-->
 		 	</tr>
 		 </table> 
	</div>
</s:form>
</div>
</body>
</html>